'use strict';

const Controller = require('egg').Controller;

class ArticleController extends Controller {
  async index() {
    // 文章列表
    let { ctx,config } = this;
    let data = await ctx.service.article.index(ctx.request.query);
    ctx.body = config.sendJson({
        code: config.code.SUCCESS,
        data: data
    })
  }
  async add() {
    // 添加文章
    let { ctx,config } = this;
    let isData = await ctx.service.article.add(ctx.request.body);
    if(isData.code === 1){
      ctx.body = config.sendJson({})
    }else{
      ctx.body = config.sendJson({
        code: config.code.MESSAGE,
        message: isData.message
      })
    }
  }
}

module.exports = ArticleController;